/**
 * 
 */
package org.dragonfire.dasm.preprocessor;

import org.dragonfire.dasm.Command;

/**
 * @author dandroid
 * @date Dec 7, 2006
 */
public class Block {

	private String[] personalDirectives = null;
	private String name = null;
	private String end = null;
	private String file = "<Unknown>";
	private int line = -1;
	private boolean inControl = true;

	public void parsePersonalDirective(Preprocessor prep, Command c) {
		if (c.getName().equalsIgnoreCase(getEnd())) {
			prep.popBlock();
			prep.setParsing(true);
		}
	}

	/**
	 * @return the inControl
	 */
	public boolean isInControl() {
		return inControl;
	}

	public void currLine(String line) {
	}

	/**
	 * @param inControl
	 *            the inControl to set
	 */
	public void setInControl(boolean inControl) {
		this.inControl = inControl;
	}

	/**
	 * @param personalDirectives
	 * @param name
	 */
	public Block(String name, String end, String... personalDirectives) {
		this.personalDirectives = personalDirectives;
		end = end.replaceAll("[^A-Za-z0-9\\.]", "");
		name = name.replaceAll("[^A-Za-z0-9\\.]", "");
		this.name = name;
		this.end = end;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	public void setEnd(String end) {
		end = end.replaceAll("[^A-Za-z0-9\\.]", "");
		this.end = end;
	}

	public String getEnd() {
		return end;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		name = name.replaceAll("[^A-Za-z0-9\\.]", "");
		this.name = name;
	}

	/**
	 * @return the personalDirectives
	 */
	public String[] getPersonalDirectives() {
		return personalDirectives;
	}

	public boolean isPersonalDirective(String name) {
		for (String dir : personalDirectives)
			if (name.equalsIgnoreCase(dir))
				return true;
		if (name.equalsIgnoreCase(getName()) || name.equalsIgnoreCase(getEnd()))
			return true;
		return false;
	}

	/**
	 * @param personalDirectives
	 *            the personalDirectives to set
	 */
	public void setPersonalDirectives(String[] personalDirectives) {
		this.personalDirectives = personalDirectives;
	}

	public String getFile() {
		return file;
	}

	public void setFile(String file) {
		this.file = file;
	}

	public int getLine() {
		return line;
	}

	public void setLine(int line) {
		this.line = line;
	}
}
